package com.chenxin.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenxin.wms.domain.ContainerEntity;
import com.chenxin.wms.domain.vo.ContainerVO;
import com.chenxin.wms.service.IContainerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenxin.common.annotation.Log;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.enums.BusinessType;
import com.chenxin.common.utils.poi.ExcelUtil;
import com.chenxin.common.core.page.TableDataInfo;

/**
 * 容器Controller
 *
 * @author loujf
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/wms/cont")
public class ContainerController extends BaseController {
    @Autowired
    private IContainerService contService;

    /**
     * 查询容器列表
     */
    @PreAuthorize("@ss.hasPermi('wms:Cont:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContainerEntity Cont) {
        startPage();
        List<ContainerVO> list = contService.selectContList(Cont);
        return getDataTable(list);
    }

    /**
     * 导出容器列表
     */
    @PreAuthorize("@ss.hasPermi('wms:Cont:export')")
    @Log(title = "容器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContainerEntity Cont) {
        List<ContainerVO> list = contService.selectContList(Cont);
        ExcelUtil<ContainerVO> util = new ExcelUtil<>(ContainerVO.class);
        util.exportExcel(response, list, "容器数据");
    }

    /**
     * 新增容器
     */
    @PreAuthorize("@ss.hasPermi('wms:Cont:add')")
    @Log(title = "容器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContainerEntity Cont) {
        return toAjax(contService.insertCont(Cont));
    }

    /**
     * 修改容器
     */
    @PreAuthorize("@ss.hasPermi('wms:Cont:edit')")
    @Log(title = "容器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContainerEntity Cont) {
        return toAjax(contService.updateCont(Cont));
    }

    /**
     * 删除容器
     */
    @PreAuthorize("@ss.hasPermi('wms:Cont:remove')")
    @Log(title = "容器", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contIds}")
    public AjaxResult remove(@PathVariable Long[] contIds) {
        return toAjax(contService.deleteContByContIds(contIds));
    }
}
